package com.dm0858.bianmin.mine.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;

import com.bumptech.glide.Glide;
import com.dm0858.bianmin.R;
import com.dm0858.bianmin.mine.base.BaseRecyclerViewAdapter;
import com.dm0858.bianmin.mine.base.BaseViewHolder;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.List;
import java.util.Locale;

public class EditPostRecyclerViewAdapter extends BaseRecyclerViewAdapter {

    private Context mContext;

    private List<LocalMedia> images;

    private OnItemClick onItemClick;

    /**
     * 构造方法
     *
     * @param mContext
     * @param resource
     * @param data
     */
    public EditPostRecyclerViewAdapter(Context mContext, int resource, List data) {
        super(mContext, resource, data);
        this.mContext = mContext;
        if (data != null) this.images = data;
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        LocalMedia image = images.get(position);
        Uri uri = Uri.parse(image.getPath());
        Glide.with(mContext).load(uri).into(holder.getImageView(R.id.img_picture));
        holder
                .setOnLongClickListener(R.id.img_picture, view -> {
                    onItemClick.onClick(position);
                    return true;
                });
    }

    @Override
    protected int getSize() {
        if (images == null) return 0;
        else return images.size();
    }

    public void setImages(List<LocalMedia> images) {
        this.images = images;
        notifyDataSetChanged();
    }

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }


    public interface OnItemClick{
        void onClick(int position);
    }
}
